package net.cyndeline.components.gameplay

import net.cyndeline.entitySystem.Component

/**
 * Stores the number of actions an entity has left to perform.
 * There is no value indicating how many actions that should be available
 * at the beginning of a turn, that is up to individual systems to set.
 */
trait ActionsLeftComponent extends Component {
  
  /**
   * The base number of actions per turn an agent may perform.
   */
  def actionsPerTurn: Int
  
  /**
   * The number of actions the unit has left to perform during its turn.
   * 
   * Note that modifying this value may lead to negative amounts, if a
   * character is to skip a number of actions due to some effect.
   * It is up to the presentation to present it as 0 unless the
   * actual value should be visible.
   */
  def actionsLeft: Int
  
  /**
   * Modifies the number of actions left by some amount. 
   * The reason for this is that no system may set a fixed
   * amount, since other systems might want to modify the amount as well
   * by some relative amount.
   * 
   * @param amount The amount to modify the number of actions left by.
   * 			   Positive numbers increase the amount of actions, negative
   *       		   numbers decrease them.
   */
  def adjustActionsLeftBy(amount: Int)
}
class ActionsLeft extends ActionsLeftComponent {
  private var actions = 0
  
  var actionsPerTurn = 1
  
  override def actionsLeft = actions
  
  override def adjustActionsLeftBy(amount: Int) {
    actions = actions + amount
  }
  
  override def copy = {
    val copy = new ActionsLeft()
    copy.adjustActionsLeftBy(actionsLeft)
    copy
  }
}